/**
 * Created with JetBrains PhpStorm.
 * User: Administrator
 * Date: 14-5-8
 * Time: 上午12:47
 * To change this template use File | Settings | File Templates.
 */

function show_error(str){
    $(".error_show").text(str);
    $(".error_show").fadeIn( function(){
        var t = setTimeout(
            function(){
                $(".error_show").fadeOut();
            },1000)
    });
}

/**
 * http 工具类
 * @type {{doPost: Function, callback: Function}}
 */
var httpHelper = {
    doPost:function(params,url){
        var result = {};
        $.ajax({
            type:"post",
            url:url,
            data:params,
            success:function Response(data){
                result = eval('(' + data + ')');
                httpHelper.callback(result);
            },
            error:function(){
                show_error("网络错误，请稍后重试！");
            }
        });
        return result;
    },
    callback:function(obj){
        switch (parseInt(obj.op_type)){
            case 1001:
                if( obj.code == '0' ){
                    var num = parseInt($(".commend b").html())+1;
                    $(".commend b").html(num);
//                    location.reload();
                } else if(obj.code == '-2'){
                    show_error("您已经赞过了！");
                }
                break;
            case 1002:
                if( obj.code == '0' ){
                    var num = parseInt($(".favorite b").html())+1;
                    $(".favorite b").html(num);
//                    location.reload();
                } else if(obj.code == '-2'){
                    show_error("您已经收藏过了！");
                }
                break;
            case 1003:
                if( obj.code == '0' ){
                    location.reload();
                    show_error("取消成功.");
                } else if(obj.code == '-2'){
                    show_error("取消失败！");
                }
                break;
            default :
                show_error("未知错误！");
                break;
        }
    }
}